package practice1_100;

public class Practice53 {
    public int maxSubArray(int[] nums) {
        int[][] maxArr=new int[nums.length][2];
        for (int i = 0; i < maxArr.length; i++) {
            maxArr[i][1]=nums[i];//0代表不选，1代表选择
        }

        maxArr[0][0]=nums[0];
        for (int i = 1; i < nums.length; i++) {
            maxArr[i][0]=Math.max(maxArr[i-1][1],maxArr[i-1][0]);
            maxArr[i][1]=Math.max(maxArr[i-1][1]+nums[i],nums[i]);
        }
        return Math.max(maxArr[nums.length-1][0],maxArr[nums.length-1][1]);
    }

    public static void main(String[] args) {
        int a=new Practice53().maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4,4,2,-57,6,4,6,-7,8,-9,-10,5,9,-7,9,-66,4,-7,7,-65,9,-68,-7,6,7,8,0,6,-8});
        System.out.println(a);
    }
}
